home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / liboctave / str-vec.h < prev    next >
C/C++ Source or Header  |  1996-11-11  |  2KB  |  108 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_str_vec_h)
  24. #define octave_str_vec_h 1
  25.  
  26. class ostream;
  27.  
  28. #include <string>
  29.  
  30. #include "Array.h"
  31.  
  32. static int
  33. str_vec_compare (const void *a_arg, const void *b_arg)
  34. {
  35.   const string *a = (const string *) a_arg;
  36.   const string *b = (const string *) b_arg;
  37.  
  38.   return a->compare (*b);
  39. }
  40.  
  41. class
  42. string_vector : public Array<string>
  43. {
  44. public:
  45.  
  46.   string_vector (void) : Array<string> () { }
  47.  
  48.   string_vector (int n) : Array<string> (n) { }
  49.  
  50.   string_vector (const char *s) : Array<string> (1, s) { }
  51.  
  52.   string_vector (const string& s) : Array<string> (1, s) { }
  53.  
  54.   string_vector (const string_vector& s) : Array<string> (s) { }
  55.  
  56.   string_vector (const char * const *s);
  57.  
  58.   string_vector (const char * const *s, int n);
  59.  
  60.   string_vector& operator = (const string_vector& s)
  61.     {
  62.       if (this != &s)
  63.     Array<string>::operator = (s);
  64.  
  65.       return *this;
  66.     }
  67.  
  68.   ~string_vector (void) { }
  69.  
  70.   int empty (void) const { return length () == 0; }
  71.  
  72.   int max_length (void) const
  73.     {
  74.       int n = length ();
  75.       int longest = 0;
  76.  
  77.       for (int i = 0; i < n; i++)
  78.     {
  79.       int tmp = elem(i).length ();
  80.  
  81.       if (tmp > longest)
  82.         longest = tmp;
  83.     }
  84.  
  85.       return longest;
  86.     }
  87.  
  88.   string& operator[] (int i) { return Array<string>::elem (i); }
  89.  
  90.   string operator[] (int i) const { return Array<string>::elem (i); }
  91.  
  92.   string_vector& qsort (void)
  93.     {
  94.       Array<string>::qsort (str_vec_compare);
  95.       return *this;
  96.     }
  97.  
  98.   ostream& list_in_columns (ostream&) const;
  99. };
  100.  
  101. #endif
  102.  
  103. /*
  104. ;;; Local Variables: ***
  105. ;;; mode: C++ ***
  106. ;;; End: ***
  107. */
  108.